package com.ruoyi.controller;


import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.service.ChatService;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@AllArgsConstructor
@RequestMapping("/zhishiku/chat")
@ApiOperation("")
public class ChatController {
    @Resource
    private final ChatService chatService;

    @PostMapping("/generateChart")
    public TableDataInfo generateChart(@RequestBody Map<String, Object> chartConfig) {
        return chatService.generateChart(chartConfig);
    }

    @PostMapping("/completion")
    TableDataInfo sendCompletion(
            @RequestBody Map<String, Object> request
    ) {
        return chatService.sendCompletion(request);
    }

    /**
     * 创建会话
     *
     * @param requestBody {
     *                    "name":string
     *                    "user_id"：（可选）string
     *                    }
     * @return
     */
    @PostMapping("/create/session")
    TableDataInfo createSession(
            @RequestBody Map<String, Object> requestBody
    ) {
        return chatService.createSession(requestBody);
    }

    /**
     * 更新会话
     *
     * @param sessionId
     * @param requestBody {
     *                    "name:string
     *                    "user_id：（可选）string
     *                    }
     * @return
     */
    @PutMapping("/session/{sessionId}")
    TableDataInfo updateSession(
            @PathVariable("sessionId") String sessionId,
            @RequestBody Map<String, Object> requestBody
    ) {
        return chatService.updateSession(sessionId, requestBody);
    }

    /**
     * 列出聊天助手的会话
     *
     * @return
     */
    @PostMapping("/getsessions")
    TableDataInfo getSessions(
            @RequestBody Map<String, Object> requestBody
    ) {
        return chatService.getSessions(requestBody);
    }

    /**
     * 获取指定聊天助手的会话
     *
     * @return
     */
    @PostMapping("/getsession")
    TableDataInfo getSession(
            @RequestBody Map<String, Object> requestBody
    ) {
        return chatService.getSession(requestBody);
    }

    /**
     * 删除聊天助手的会话
     *
     * @param requestBody {
     *                    "ids":list[string]
     *                    }
     * @return
     */
    @PostMapping("/deleteSessions")
    TableDataInfo deleteSessions(
            @RequestBody Map<String, Object> requestBody
    ) {
        return chatService.deleteSessions(requestBody);
    }
}
